package demoMod.invincibleOne.cards.invincible;

import basemod.helpers.CardModifierManager;
import com.badlogic.gdx.math.Vector2;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.SpawnMonsterAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.monsters.exordium.Cultist;
import com.megacrit.cardcrawl.powers.RitualPower;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.AbstractCardEnum;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.relics.TaskGoal;

public class UnmatchedPower extends AbstractInvincibleCard {
    public static final String ID = InvincibleOneMod.makeID("UnmatchedPower");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/UnmatchedPower.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = AbstractCardEnum.LEGENDARY;
    private static final CardTarget TARGET = CardTarget.NONE;
    private static final int COST = -2;
    private static final Vector2 vector2 = new Vector2(180.0F * Settings.scale, 0.0F);

    public UnmatchedPower() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        this.baseMagicNumber = this.magicNumber = 1;
        CardModifierManager.addModifier(this, modifier);
        this.tags.add(CardTagsEnum.ALERT);
    }

    @Override
    public boolean onBattleStart() {
        TaskGoal.AddToAlertQueue(1, new TaskGoal.AlertLambda() {
            @Override
            public void run() {
                for (int i=0;i<magicNumber;i++) {
                    AbstractMonster m = new Cultist(0.0F, 0.0F, true);
                    m.drawX = Settings.WIDTH / 2.0F - vector2.x - 100.0F * Settings.scale;
                    m.drawY = Settings.HEIGHT * 0.33F - vector2.y;
                    addToBot(new SpawnMonsterAction(m, true));
                    addToBot(new AbstractGameAction() {
                        @Override
                        public void update() {
                            m.createIntent();
                            addToTop(new ApplyPowerAction(m, m, new RitualPower(m, 2, false)));
                            isDone = true;
                        }
                    });
                    vector2.rotate(45.0F);
                }
            }
        });
        return true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeMagicNumber(1);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }
}
